package com.mdd.admin.controller.driver;

import com.mdd.admin.service.IDriverInfoService;
import com.mdd.admin.validate.DriverInfoCreateValidate;
import com.mdd.admin.validate.DriverInfoUpdateValidate;
import com.mdd.admin.validate.DriverInfoSearchValidate;
import com.mdd.admin.vo.DriverInfoVo;
import com.mdd.admin.vo.DriverInfoDetailVo;
import com.mdd.common.aop.Log;
import com.mdd.common.base.page.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.IdValidate;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("api/driverInfo")
@Api(tags = "驾驶员信息管理")
public class DriverInfoController {

    @Resource
    IDriverInfoService iUmsDriverInfoService;

    @GetMapping("/list")
    @ApiOperation(value="驾驶员信息列表")
    public AjaxResult<PageResult<DriverInfoVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated DriverInfoSearchValidate searchValidate) {
        PageResult<DriverInfoVo> list = iUmsDriverInfoService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="驾驶员信息详情")
    public AjaxResult<DriverInfoDetailVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        DriverInfoDetailVo detail = iUmsDriverInfoService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "驾驶员信息新增")
    @PostMapping("/add")
    @ApiOperation(value="驾驶员信息新增")
    public AjaxResult<Object> add(@Validated @RequestBody DriverInfoCreateValidate createValidate) {
        iUmsDriverInfoService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "驾驶员信息编辑")
    @PostMapping("/edit")
    @ApiOperation(value="驾驶员信息编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody DriverInfoUpdateValidate updateValidate) {
        iUmsDriverInfoService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "驾驶员信息删除")
    @PostMapping("/del")
    @ApiOperation(value="驾驶员信息删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iUmsDriverInfoService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
